const express = require('express')
const path = require('path')
const bodyParser = require('body-parser')
const multer = require('multer')
const app = express()

app.use(bodyParser.urlencoded({extended:false}))
app.use(bodyParser.json())
app.use('/static',express.static(path.join(__dirname,'public')))
app.use(express.static(path.join(__dirname,'files')))

let upload = multer({dest:"./files/images"})
app.post('/upload',upload.single('myfile'),(req,res)=>{
    let jsonObj = {
        msg:'存储成功',
        filepath:'/images' + path.basename(req.file.path)
    }
    res.send(JSON.stringify(jsonObj))
})
let server = app.listen(3000,'127.0.0.1',()=>{
    let host = server.address().address
    let port = server.address().port
    console.log(`APP listening ${host} on port ${port}`)
})